package com.craftcomputing.client.SearchResult;

import org.gwtwidgets.client.util.WindowUtils;

import com.craftcomputing.client.Entry.CodeEntry;
import com.craftcomputing.client.Entry.EntryPanel;
import com.craftcomputing.client.Listeners.SearchResultListeners.*;
import com.craftcomputing.client.SearchResult.Label.*;
import com.google.gwt.user.client.HTTPRequest;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.json.client.JSONValue;

public class CodeSearchResult extends SearchResult{
	/**
	* @wbp.parser.constructor
	*/
	public CodeSearchResult(){}
	public CodeSearchResult(boolean searchWithin){
		super(searchWithin);
	}
	public Widget makeEntryLabel(JSONValue json){
		return new CodeSearchResultLabel(json);
	}
	public EntryPanel makeEntryPanel(){
		return new CodeEntry();
	}
	public String entryName(){
		return "Code";
	}
	public void doSearch(String tbText, boolean findCount){
		if(findCount){
      	  String searchText = "/python/codesamples/count?search=" + tbText;
		  HTTPRequest.asyncGet(searchText, new JSONCountResponseTextHandler(this));		        	  
		}
		String offsetStr = WindowUtils.getLocation().getParameter("offset");
		if(offsetStr != null) offset = Integer.parseInt(offsetStr);
		String searchText = "/python/codesamples?search=" + tbText + "&offset=" + offset;
		HTTPRequest.asyncGet(searchText, new JSONSearchResponseTextHandler(this, tbText));
		setStyleName("gwt-SearchResultsPanel");
	}
}
